<template>
  <el-select
    v-model="selectValue"
    filterable
    placeholder="请选择"
    style="width:90px"
    :disabled="disabled"
    @change="changeIntyear"
  >
    <el-option
      v-for="item in budgetYearList"
      :key="item.intyear"
      :label="item.intyear"
      :value="item.intyear"
    />
  </el-select>

</template>
<script>
import { mapGetters } from 'vuex'
export default {
  name: 'BudgetYear',
  props: {
    value: {
      type: [Number, String],
      default: ''
    },
    disabled: {
      type: [Boolean],
      default: false
    },
    isSetDefaultYear: {
      type: [Boolean],
      default: true
    }
  },
  data() {
    return {

    }
  },
  computed: {
    ...mapGetters(['budgetYearList']),
    selectValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    }
  },
  created() {
    this.$store.dispatch('common/getYearList').then(() => {
      if (this.isSetDefaultYear) {
        this.selectValue = this.budgetYearList[0]['intyear']
        this.$emit('change', this.budgetYearList[0]['intyear'])
      }
    }) // 获取预算年度
  },
  methods: {
    changeIntyear(val) {
      this.$emit('change', val)
    }
  }
}
</script>
